(* OCamllex input file for APost *)

{ 
open Parser;;
open Lexing;;

exception Eof;;

let line_number = ref 1;;
}

rule token = parse
    [' ' '\t' ]      { token lexbuf }
  | "\n"             { line_number := !line_number + 1; token lexbuf }
(* Keywords *)
  | ['a'-'z' '_']+   { COMMAND ((lexeme lexbuf),!line_number) }
  | "{"              { LBRACE !line_number }
  | "}"              { RBRACE !line_number }
  | "("              { LPAREN !line_number }
  | ")"              { RPAREN !line_number }
  | "+"              { ADD !line_number }
  | "-"              { SUB !line_number }
  | "*"              { MUL !line_number }
  | "/"              { DIV !line_number }
  | "%"              { MOD !line_number }
  | "="              { EQ !line_number }
  | "<"              { LT !line_number }
  | ">"              { GT !line_number }
  | "TRUE"           { BOOLEAN (true, !line_number) }
  | "FALSE"          { BOOLEAN (false, !line_number) }
(* Constants *)
  | ['0'-'9']+       { INTEGER (int_of_string (lexeme lexbuf), !line_number) }
  | "\""             { let s = str_lex "" lexbuf in STRING (s, !line_number) }
  | eof              { raise Eof }

and str_lex buf = parse
    "\""             { buf }
  | "\\n"            { str_lex (buf ^ "\n") lexbuf}
  | "\n"             { line_number := !line_number + 1; str_lex (buf ^ "\n") lexbuf }
  | _                { str_lex (buf ^ (lexeme lexbuf)) lexbuf}

